import {RequestAdapter} from "./RequestAdapter";

export class WxRequest extends RequestAdapter {

    get(url: string, query: any): Promise {
        return new Promise((resolve, reject) => {
            wx.request({
                url: url,
                data: query,
                success: res => resolve(res.data),
                fail: res => reject(res)
            })
        });
    }

    post(url: string, body: any): Promise {
        return new Promise((resolve, reject) => {
            wx.request({
                url: url,
                data: body,
                method: 'POST',
                success: res => resolve(res.data),
                fail: res => reject(res)
            })
        });
    }

    put(url: string, body: any): Promise {
        return new Promise((resolve, reject) => {
            wx.request({
                url: url,
                data: body,
                method: 'PUT',
                success: res => resolve(res.data),
                fail: res => reject(res)
            })
        });
    }

    delete(url: string, query: any): Promise {
        return new Promise((resolve, reject) => {
            wx.request({
                url: url,
                data: query,
                method: 'DELETE',
                success: res => resolve(res.data),
                fail: res => reject(res)
            })
        });
    }
}